package org.game.module.chatbo.testcmd;

import com.sojoys.artifact.core.IServer;
import com.sojoys.artifact.factory.session.ISession;
import com.sojoys.artifact.tools.ToolList;
import org.game.db.bean.Player;
import org.game.module.rolebo.RoleBO;
import org.game.protobuf.c2s.C2SRoleMsg;

import java.util.List;

/**
 * Created by fxf on 2018-3-12.
 */
public class RoomTest {

    public static byte[] dispatcher(Player player, List<String> cmds){
        int index = ToolList.getInt(1, cmds);
        byte[] result = new byte[0];
        switch (index){
            case 1:
                result = changeRoom(player, cmds);
                break;
            case 2:
                result = unlockRoom(player, cmds);
                break;

        }
        return result;
    }

    public static byte[] changeRoom(Player player, List<String> cmds){
        int roleCid = ToolList.getInt(2, cmds);
        int roomCid = ToolList.getInt(3, cmds);
        RoleBO roleBO = IServer.getModules().getModule(RoleBO.classCode,RoleBO.class);
        ISession session = player.getPlayerProxy().getSession();

        C2SRoleMsg.ChangeRoom.Builder builder = C2SRoleMsg.ChangeRoom.newBuilder();
        builder.setRoleCid(roleCid)
                .setRoomCid(roomCid);
        return roleBO.changeRoom(session,builder.build());
    }

    public static byte[] unlockRoom(Player player, List<String> cmds){
        int roomCid = ToolList.getInt(2, cmds);
        RoleBO roleBO = IServer.getModules().getModule(RoleBO.classCode,RoleBO.class);
        ISession session = player.getPlayerProxy().getSession();

        C2SRoleMsg.UnlockRoom.Builder builder = C2SRoleMsg.UnlockRoom.newBuilder();
        builder.setRoomCid(roomCid);
        return roleBO.unlockRoom(session,builder.build());
    }
}
